/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.com.codefire.stream;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author human
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String filePath = "./file.txt";

        try {
            System.out.print("Enter string: ");
            String readLine = br.readLine();

            byte[] bytes = readLine.getBytes();

            FileOutputStream fos = new FileOutputStream(filePath);

            fos.write(bytes);
            fos.write('\n');
            //            fos.flush();
            //            fos.write(bytes);

            fos.close();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            try (FileInputStream fis = new FileInputStream(filePath)) {
                byte[] array = new byte[fis.available()];
                int count = fis.read(array);
                System.out.println(count);
                System.out.println(new String(array));
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
//        System.getProperties();
    }
}
